package com.paradogs.demo.client.demo;

import com.paradogs.framework.core.msg.PRMsg;
import com.paradogs.framework.core.msg.MsgHeader;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: yumi
 * @date: 2023/9/23  13:44
 * @Description: TODO
 */
@Slf4j
public class Client {

    public static <T> void send(Channel channel, String route, T data) {
        PRMsg msg = new PRMsg(data);
        if (msg == null) {
            msg = new PRMsg();
        }
        if (msg.getMsgHeader() == null) {
            msg.setMsgHeader(new MsgHeader());
        }
        msg.getMsgHeader().setRoute(route);

        if (channel != null) {
            channel.writeAndFlush(msg);
            log.info(">>>>> [{}] ", msg.getMsgHeader().getRoute());
        } else {
            log.warn("channel is null, route: {}", route);
        }
    }
}
